package ${package_name}.controller;
<#--import com.evada.inno.core.annotation.Rest;-->
import ${package_name}.dto.TableDataDto;

import com.yzy.${project_name}.common.persistence.model.${table_name};
import com.yzy.${project_name}.system.dto.${table_name}Dto;
import com.yzy.${project_name}.common.persistence.dao.${table_name}Mapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.google.common.collect.Lists;

import com.yzy.soft.core.base.controller.BaseController;
import com.yzy.soft.core.base.tips.ErrorTip;
import com.yzy.soft.core.base.tips.Tip;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.Date;
import java.util.List;

/**
* 描述：${table_annotation}控制层
* @author ${author}
* @date ${date}
*/
@Api(value="${table_annotation}控制层")
@RestController
@RequestMapping("/${class_requestMapping}")
public class ${table_name}Controller extends BaseController{

    private static final Logger logger= LoggerFactory.getLogger(${table_name}Controller.class);
    //@Autowired
    //private I${table_name}Service ${table_name?uncap_first}Service;
    
    @Autowired
    private ${table_name}Mapper ${table_name?uncap_first}Mapper;

    
    
    /**
    * 描述：查询 ${table_annotation}列表
    */
    @ApiOperation(value="查询${table_annotation}")
    @GetMapping(value = "/page/{id}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public TableDataDto getAll(@RequestParam(name = "page", defaultValue = "1", required = true) int page, @RequestParam(name = "limit", defaultValue = "10", required = true) int pageSize)throws Exception {
    
        Wrapper<${table_name}> ${table_name?uncap_first}=new EntityWrapper<${table_name}>();
        page=(page-1)*pageSize;
        pageSize=page+pageSize;
        List<${table_name}> result=${table_name?uncap_first}Mapper.selectPage(new RowBounds(page,pageSize),${table_name?uncap_first});
        TableDataDto tableDataDto=new TableDataDto();
        tableDataDto.setCode("00");
        tableDataDto.setMsg("000");
        tableDataDto.setCount(${table_name?uncap_first}Mapper.selectCount(${table_name?uncap_first}));
        tableDataDto.setData(result);
        return tableDataDto;
    }
    
    /**
    * 描述：根据Id 查询 ${table_annotation}
    * @param id  ${table_annotation}id
    */
    @ApiOperation(value="查询${table_annotation}")
    @GetMapping(value = "/{id}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ${table_name} findById(@PathVariable("id") String id)throws Exception {
        logger.info("${table_name}Controller findById: {}",id);
        return ${table_name?uncap_first}Mapper.selectById(id);
        <#--AssertUtils.checkResourceFound(${table_name?uncap_first}Dto);-->
    }

    /**
    * 描述:创建${table_annotation}
    * @param ${table_name?uncap_first}DTO  ${table_annotation}DTO
    */
    @ApiOperation(value="创建${table_annotation}")
    @PostMapping("")
    public Tip create(@ModelAttribute ${table_name} ${table_name?uncap_first}) {
        logger.info("${table_name}Controller create: {}",${table_name?uncap_first});
        ${table_name?uncap_first}.setCreatetime(new Date());
        ${table_name?uncap_first}.setLastupdatetime(new Date());
        Integer result=${table_name?uncap_first}Mapper.insert(${table_name?uncap_first});
        return SUCCESS_TIP;
    }

   /**
    * 描述：删除${table_annotation}
    * @param id ${table_annotation}id
    */
    @ApiOperation(value="删除${table_annotation}")
    @DeleteMapping("/{id}")
    public Tip delete(@RequestParam(name="ids[]",required = false) String[] ${table_name?uncap_first},@PathVariable(name="id",required = false) String id) {
        //Collections.<String>
        if(StringUtils.isNotBlank(id)){
            logger.info("${table_name}Controller deleteById: {}",id);
            Integer result=${table_name?uncap_first}Mapper.deleteById(id);
        }else if(${table_name?uncap_first}.length!=0){
            Integer result=${table_name?uncap_first}Mapper.deleteBatchIds(Lists.newArrayList(${table_name?uncap_first}) );
        }
        return SUCCESS_TIP;
    }
    @ApiOperation(value="批量删除${table_annotation}")
    @DeleteMapping("/")
    public Tip delete1(@RequestParam(name="ids[]",required = false) String[] ${table_name?uncap_first}) {
        if(${table_name?uncap_first}.length!=0){
           Integer result=${table_name?uncap_first}Mapper.deleteBatchIds(Lists.newArrayList(${table_name?uncap_first}) );
        }
        return SUCCESS_TIP;
    }


    /**
    * 描述：更新${table_annotation}
    * @param id ${table_annotation}id
    */
    @ApiOperation(value="更新${table_annotation}")
    @PutMapping(value = "", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Tip update${table_name}(@ModelAttribute ${table_name} ${table_name?uncap_first}) throws Exception {
        ${table_name?uncap_first}.setLastupdatetime(new Date());
        Integer result=${table_name?uncap_first}Mapper.updateById(${table_name?uncap_first});
        return SUCCESS_TIP;
    }

    @GetMapping("/by")
    public TableDataDto getCadtion(@ModelAttribute ${table_name} ${table_name?uncap_first}) {
        Wrapper<${table_name}> wrapper = new EntityWrapper<${table_name}>();
        wrapper.where("versionId={0}", ${table_name?uncap_first}.getVersionid());
        List<${table_name}> result = ${table_name?uncap_first}Mapper.selectList(wrapper);
        TableDataDto tableDataDto = new TableDataDto();
        tableDataDto.setCode("00");
        tableDataDto.setMsg("000");
        tableDataDto.setCount(result.size());
        tableDataDto.setData(result);
        return tableDataDto;
    }

    @PutMapping("/status/{id}")
    <#if (idType = 'int'|| idType = 'INT'|| idType = 'Integer')>
    public Tip status(@PathVariable("id")Integer id) {
    </#if>
    <#if (idType = 'String'|| idType = 'STRING')>
    public Tip status(@PathVariable("id")String id) {
    </#if>
        logger.info("${table_name}Controller status 变更状态: {}",id);
        Integer result=${table_name?uncap_first}Mapper.status(id);
        if(null==result){
           return new ErrorTip(500,"s");
        }
        return SUCCESS_TIP;
    }

    @GetMapping("/${table_name?uncap_first}Id/{${table_name?uncap_first}Id}")
    public TableDataDto getbyAccountId(@PathVariable(name="${table_name?uncap_first}Id") String ${table_name?uncap_first}Id,@RequestParam(name="page",defaultValue = "1",required = true) int page, @RequestParam(name="limit",defaultValue = "10",required = true) int pageSize) {
       Wrapper<${table_name}> ${table_name?uncap_first}Wrapper=new EntityWrapper<>();
       ${table_name?uncap_first}Wrapper.where("accountid={0}",${table_name?uncap_first}Id);
       page=(page-1)*pageSize;
       pageSize=page+pageSize;
       List<${table_name}> result=${table_name?uncap_first}Mapper.selectPage(new RowBounds(page,pageSize),${table_name?uncap_first}Wrapper);
       TableDataDto tableDataDto=new TableDataDto();
        tableDataDto.setCode("00");
        tableDataDto.setMsg("000");
        tableDataDto.setCount(${table_name?uncap_first}Mapper.selectCount(${table_name?uncap_first}Wrapper));
        tableDataDto.setData(result);
        return tableDataDto;
    }
    @ApiOperation("批量将费用归档设置成弃用状态")
    @PostMapping("/batchNuUse")
    <#if (idType = 'int'|| idType = 'INT'|| idType = 'Integer')>
    public Tip batchNuUse(@RequestParam(name="ids[]",required = false) Integer[] ${table_name?uncap_first}) {
    </#if>
    <#if (idType = 'String'|| idType = 'STRING')>
    public Tip batchNuUse(@RequestParam(name="ids[]",required = false) String[] ${table_name?uncap_first}) {
    </#if>
        if(${table_name?uncap_first}.length!=0){
           Integer result=${table_name?uncap_first}Mapper.batchNuUseIds(Lists.newArrayList(${table_name?uncap_first}) );
        }
        return SUCCESS_TIP;
    }
    @ApiOperation("批量将费用归档设置成可用状态")
    @PostMapping("/batchUse")
    <#if (idType = 'int'|| idType = 'INT'|| idType = 'Integer')>
    public Tip batchUse(@RequestParam(name="ids[]",required = false) Integer[] ${table_name?uncap_first}) {
    </#if>
    <#if (idType = 'String'|| idType = 'STRING')>
    public Tip batchUse(@RequestParam(name="ids[]",required = false) String[] ${table_name?uncap_first}) {
    </#if>
        if(${table_name?uncap_first}.length!=0){
            Integer result=${table_name?uncap_first}Mapper.batchUseIds(Lists.newArrayList(${table_name?uncap_first}) );
        }
        return SUCCESS_TIP;
    }
}